<?
	require_once("../cBasic/950cons.php");
	$sTable=$_GET['table'];
	$aColumns = array();
	$sQuery="select  * from $sTable limit 0,1";
	$rResult = mysql_query( $sQuery, $con ) or die(mysql_error());
	$fields = mysql_num_fields($rResult);
	for ($i=0; $i<$fields; $i++){
		$aColumns[$i] = mysql_field_name ($rResult,$i);
	}
	
	$strkey='';
	$strvalue='';
	$setvalue='';
	for ($i=0; $i<count($aColumns); $i++){
		if (isset($_GET[$aColumns[$i]])){
			$strkey .= $aColumns[$i];
			$strvalue .= "'".$_GET[$aColumns[$i]]."'";
			$setvalue .= $aColumns[$i]."='".$_GET[$aColumns[$i]]."'";
			if ($i!= (count($aColumns)-2)){
				$strkey .= ",";
				$strvalue .= ",";
				$setvalue .= ",";
			}
		}
	}
	
	switch ($_GET['edittype']){
		case 'add':
			$sQuery= "INSERT INTO ".$sTable." (".$strkey.") value(".$strvalue.")";
			break;
		case 'update':
			$sQuery= "UPDATE ".$sTable." SET ".$setvalue." where ".mysql_field_name ($rResult,0)."=".$_GET['recid'];
			break;
		case 'delete':
			$sQuery= "UPDATE ".$sTable." SET Status = 0 where ".mysql_field_name ($rResult,0)."='".$_GET['recid']."'";
			break;
	}
	mysql_query( $sQuery, $con ) or die(mysql_error());
	mysql_close($con);
	
	echo $_GET['edittype']." Success";
?>